home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / flight-of-the-museum.swf / scripts / com / google / analytics / debug / Alert.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  3.3 KB  |  130 lines

  1. package com.google.analytics.debug
  2. {
  3.    import flash.events.TextEvent;
  4.    
  5.    public class Alert extends Label
  6.    {
  7.        
  8.       
  9.       public var autoClose:Boolean = true;
  10.       
  11.       public var actionOnNextLine:Boolean = true;
  12.       
  13.       private var _actions:Array;
  14.       
  15.       public function Alert(text:String, actions:Array, tag:String = "uiAlert", color:uint = 0, alignement:Align = null, stickToEdge:Boolean = false, actionOnNextLine:Boolean = true)
  16.       {
  17.          if(color == 0)
  18.          {
  19.             color = uint(Style.alertColor);
  20.          }
  21.          if(alignement == null)
  22.          {
  23.             alignement = Align.center;
  24.          }
  25.          super(text,tag,color,alignement,stickToEdge);
  26.          this.selectable = true;
  27.          super.mouseChildren = true;
  28.          this.buttonMode = true;
  29.          this.mouseEnabled = true;
  30.          this.useHandCursor = true;
  31.          this.actionOnNextLine = actionOnNextLine;
  32.          _actions = [];
  33.          for(var i:int = 0; i < actions.length; i++)
  34.          {
  35.             actions[i].container = this;
  36.             _actions.push(actions[i]);
  37.          }
  38.       }
  39.       
  40.       private function _defineActions() : void
  41.       {
  42.          var action:AlertAction = null;
  43.          var str:* = "";
  44.          if(actionOnNextLine)
  45.          {
  46.             str += "\n";
  47.          }
  48.          else
  49.          {
  50.             str += " |";
  51.          }
  52.          str += " ";
  53.          var actions:Array = [];
  54.          for(var i:int = 0; i < _actions.length; i++)
  55.          {
  56.             action = _actions[i];
  57.             actions.push("<a href=\"event:" + action.activator + "\">" + action.name + "</a>");
  58.          }
  59.          str += actions.join(" | ");
  60.          appendText(str,"uiAlertAction");
  61.       }
  62.       
  63.       protected function isValidAction(action:String) : Boolean
  64.       {
  65.          for(var i:int = 0; i < _actions.length; i++)
  66.          {
  67.             if(action == _actions[i].activator)
  68.             {
  69.                return true;
  70.             }
  71.          }
  72.          return false;
  73.       }
  74.       
  75.       override protected function layout() : void
  76.       {
  77.          super.layout();
  78.          _defineActions();
  79.       }
  80.       
  81.       protected function getAction(name:String) : AlertAction
  82.       {
  83.          for(var i:int = 0; i < _actions.length; i++)
  84.          {
  85.             if(name == _actions[i].activator)
  86.             {
  87.                return _actions[i];
  88.             }
  89.          }
  90.          return null;
  91.       }
  92.       
  93.       protected function spaces(num:int) : String
  94.       {
  95.          var str:String = "";
  96.          var spc:String = "          ";
  97.          for(var i:int = 0; i < num + 1; i++)
  98.          {
  99.             str += spc;
  100.          }
  101.          return str;
  102.       }
  103.       
  104.       override public function onLink(event:TextEvent) : void
  105.       {
  106.          var action:AlertAction = null;
  107.          if(isValidAction(event.text))
  108.          {
  109.             action = getAction(event.text);
  110.             if(action)
  111.             {
  112.                action.execute();
  113.             }
  114.          }
  115.          if(autoClose)
  116.          {
  117.             close();
  118.          }
  119.       }
  120.       
  121.       public function close() : void
  122.       {
  123.          if(parent != null)
  124.          {
  125.             parent.removeChild(this);
  126.          }
  127.       }
  128.    }
  129. }
  130.